package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.entity.Setmeal;
import com.sky.mapper.SetmealMapper;
import com.sky.result.Result;
import com.sky.service.UserSetmealService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserSetmealServiceImpl implements UserSetmealService {
	
	private final SetmealMapper setmealMapper;
	
	public UserSetmealServiceImpl(SetmealMapper setmealMapper) {
		this.setmealMapper = setmealMapper;
	}
	
	@Override
	@Cacheable(cacheNames = "SetmealCache", key = "#categoryId")
	public Result list(Long categoryId) {
		List<Setmeal> setmeals = setmealMapper.getSetmealBy(null, categoryId, null);
		if (setmeals.isEmpty()) {
			return Result.error(MessageConstant.DISH_NOT_FOUND);
		}
		return Result.success(setmeals);
	}
}
